Part Number Hot Search : 
47M35 FMMZ5252 5TRPB MB156 AAT4285 SAB9083 Q2547 AM252
Product Description
Full Text Search
 

To Download AN3332 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  january 2011 doc id 18399 rev 1 1/7 AN3332 application note generating pwm signals using stm8s-discovery application overview this application user manual provides a short description of how to use the timer 2 peripheral (tim2) to generate three pwm signals. even though the stm8s-discovery is built around an stm8s105c6t6, it allows evaluation of the main features of all the stm8s mcus. reference documents stm8s-discovery evaluation board user manual (um0817). developing and debugging stm8s-discovery application user manual (um0834). www.st.com
application description AN3332 2/7 doc id 18399 rev 1 1 application description 1.1 hardware requirement no additional hardware is required on the stm8s-discovery board. an oscilloscope is needed as an external resource. 1.2 application schematics figure 1. application schematics 1.3 application principle this application is based on the use of the stm8s tim2 in pwm (pulse width modulation) mode to generate 3 pwm signals. the generation process is presented in figure 2 . 34 -  3 0$ 0$  0! ai 4)- '0)/
AN3332 application description doc id 18399 rev 1 3/7 figure 2. pwm generation principle tim2 counts up from 0 to the auto-reload register value (tim2_arr) according to the tim2 counter clock. when the counter value equals the compare/capture register (tim2_ccrxx) value channel x signal is set to 0. when the counter value reaches the tim2_arr value the counter is reset and channel x signal is set to 1. by configuring the tim2_ccrxx and tim2_arr registers you can easily modify the duty cycle and frequency of the pwm signals generated (see section 2: software description ). by default the application provides the 3 pwm signals as specified in ta bl e 1 . note: it is possible to configure the afr option byte to get channel 3 on pd2 also. table 1. default pwm signals signal duty cycle frequency i/o pin header connector channel 1 pwm 50% 2 khz pd4 cn4.9 channel 2 pwm 25% 2 khz pd3 cn4.8 channel 3 pwm 75% 2 khz pa3 cn1.9
software description AN3332 4/7 doc id 18399 rev 1 2 software description this example uses the stm8s standard firmware library to control the general purpose functions. to generate the pwm signals the tim2 peripheral must be configured as follows: output state enabled for each channel output compare active low for each channel preload register enabled for each channel pwm output signal frequency = 2 khz: ? the timer source clock frequency is 2 mhz (f cpu by default) and the prescaler is set to 1 to obtain a tim2 counter clock of 2 mhz. ? pwm output signal frequency can be set according to the following equation: pwm output signal frequency = tim2 counter clock/(tim2_arr + 1) (in our case tim2_arr = 999, so pwm output signal frequency is 2 khz) pwm mode for each channel. to obtain a different pwm duty cycle value on each channel the tim2_ccrxx register must be set according to this equation: channel x duty cycle = [tim2_ccrxx/(tim2_arr + 1)] * 100 by default we have: ? channel 1: tim2_ccr1x register value is 500, so channel 1 of tim2 generates a pwm signal with a frequency of 2 khz and a duty cycle of 50%. ? channel 2: tim2_ccr2x register value is 750, so channel 2 of tim2 generates a pwm signal with a frequency of 2 khz and a duty cycle of 75%. ? channel 3: tim2_ccr3x register value is 250, so channel 3 of tim2 generates a pwm signal with a frequency of 2 khz and a duty cycle of 25%. 2.1 stm8s standard firmware library configuration the stm8s_conf.h file of the stm8s standard firmware library is used to configure the library by enabling the peripheral functions used by the application. the following define statements must be present: #define _gpio 1 enables the gpios #define _tim2 1 enables the tim2
AN3332 software description doc id 18399 rev 1 5/7 2.2 application software flowcharts 2.2.1 main loop flowchart figure 3. main loop flowchart ai 3tart 3ettimerfrequency #onfigure#hannel %nable4)-?!22 %nd 3etstimerprescalerfactor 0rograms4-)?!22auto reloadregisterto 0rograms4)-?##2xcapturecompareregisters %nables07-mode %nablesoutputstate 3electoutputcomparepolaritytolow %nablespreloadregister #onfigurechannel #onfigurechannel %nabletimer 'enerationof07-signals on0! 0$ 0$
revision history AN3332 6/7 doc id 18399 rev 1 3 revision history table 2. document revision history date revision changes 15-jan-2011 1 initial release. this document replaces um0856.
AN3332 doc id 18399 rev 1 7/7 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a parti cular purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. unless expressly approved in writing by an authorized st representative, st products are not recommended, authorized or warranted for use in milita ry, air craft, space, life saving, or life sustaining applications, nor in products or systems where failure or malfunction may result in personal injury, death, or severe property or environmental damage. st products which are not specified as "automotive grade" may only be used in automotive applications at user?s own risk. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2011 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN3332

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X